<?php
/*

  Copyright 2005  Blackhacker (email : bh@blackhacker.net)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

INSTRUCTIONS
============

Add the following code to your template where you want your tags to appear:

<?php the_bunny_tags(); ?>

The keywords will appear as links wrapped in <p class="tags">Tags: ...</p>. You may want to add CSS to style the list.

If you want other html, you can try things like the following (thanks, Scott):

<?php the_bunny_tags("<ul><li>", "</li></ul>", "</li><li>"); ?>

If you want keywords to be translated as tags for posts which do not have tags defined, change the setting below. Attention! your keyword list must be stored in a custom field 'keywords' and be a comma-separated list -- otherwise you will need to edit the



 function get_bunny_tags_list().

WARNING: if your pages aren't utf-8 and you use non-ascii characters in your tags, your tags might not get indexed properly.

*/


/*
CHANGELOG
=========
0.1  - Initial release 03.30.2006

CREDITS
=======

*/
require_once('bh-widgets/BH_Widget_Base.php');
require_once('BH_Tags.php');

class BH_Related_Tags_Widget extends BH_Widget_Base {

	function widget($args) {
		extract($args);
		if (!is_tag()) return;

		$tag_query_vay = get_query_var("tag");
		$title = $this->get_attribute('title');
		$url = get_bloginfo('url') .'/tag/';

		$tags_count = BH_Tags::get_tags_count(0,$tag_query_vay );

		if (!$tags_count) return;

		echo "$before_widget\n";
		echo $this->get_widget_start_tag($args);
		echo $before_title . urldecode(sprintf($title, $tag_query_vay)) . $after_title . "\n";
		echo "$before_list\n";

		foreach ($tags_count as $tag => $freq) {
			echo "$before_item\n";
			echo BH_Tags::tag_link($tag, $url, "$tag($freq)") . "\n";
			echo "$after_item\n";
		}

		echo "$after_list\n";
		echo $this->get_widget_end_tag($args);
		echo "$after_widget\n";
	}

	function control() {
		$title = $this->get_attribute('title');

		if($this->get_request_param('submit') ) {
			$title = $this->get_request_param('title');
			$this->set_attribute('title', $title);
		}

		echo '<label>Title</label>';
		echo '<input type="text" id="" name="title" value="'. $title .'" /><br/>'. "\n";
		echo '<input type="hidden" name="'.$this->get_request_param_name('submit').'" value="submit" />'. "\n";;
	}
}

bh_widgets_register_class('BH_Related_Tags_Widget');

?>
